
import { Observable } from 'rxjs'
const observable = new Observable((observer) => {
  let index = 0
  let timer = setInterval(() => {
    observer.next(index++)
    if (index === 3) {
      // observer.complete()// 终止
      observer.error('错误信息')
      clearTimeout(timer)
    }
  }, 1000)
})

observable.subscribe(
  {
    next: (value) => {
      console.log(value)
    },
    complete: () => {
      console.log('终止了')
    },
    error: (err) => {
      console.log(err)
    }
  }
)
